package aimis.dto;

import lombok.Data;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

@Data
public class PageQuery {
    private String sortBy;
    private Boolean desc;
    private Integer pageSize;
    private Integer pageNum;
    public Pageable toPageable()
    {
        if(sortBy!=null&&sortBy.isBlank())
            sortBy=null;
        if(desc==null)
            desc=false;
        var pageable = PageRequest.of(pageNum, pageSize, Sort.by(desc? Sort.Direction.DESC: Sort.Direction.ASC,sortBy));
        return pageable;
    }
}
